<template>
  <div class="app-container">


    <div>

      ededed
    </div>
  </div>
</template>

<script>
export default {
  name: "Wenjuan",
  data() {
    return {
      nickname:"whi"

    }
  },
  created() {
    this.getWebsocket();
  },
  methods: {
    getWebsocket(){
      //创建一个websocket对象
      let ws = new WebSocket("ws://localhost:8888")

      //连接成功时触发
      ws.onopen = function (event) {
        console.log("连接成功");
        ws.send("{\"nickname\":\"" + this.nickname + "\",\"code\":\"1001\"}");
      }

      //连接失败时触发
      ws.onerror = function (event) {
        console.log("连接失败");
      }

      //接收消息时触发
      ws.onmessage = function (event) {
        console.log(event)
      }

      //连接关闭时触发
      ws.onclose = function (event) {
        console.log("连接关闭")
      }
    }
  }
}
</script>

<style scoped>

</style>
